#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;

#define N 1000000
char arr[N + 5] = {0};


int main()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    arr[0] = '1';
    for(int i = 0; i < n; i++)
    {
        char cur = str[i];
        int len = strlen(arr) - 1;
        //cout << "i : " << i << " len : " << len << endl;
        if(len == 0) 
        {
            arr[1] = cur;
            continue;
        }
        //std::cout << "arr: " << arr;
        int left = 0, right = len;
        while(left < right)
        {
            int mid = (right - left) / 2 + left + 1;
            if(arr[mid] <= cur)
            {
                left = mid;
            }
            else
            {
                right = mid - 1;
            }
        }
        //std::cout << "left: " << left << "right: " << right << endl;
        arr[right + 1] = cur;
        len = strlen(arr);
        // for(int i = 0; i < len; i++) cout << arr[i] << " ";
        // cout << endl;
    }
    int len = strlen(arr) - 1;

    cout << n - len;
    return 0;
}